﻿Public Class frmpedido
    Dim precio(5) As Integer
    Dim i As Integer = 0
    Dim total As Integer = 0
    Dim l As Integer = 0
    Dim w As Integer = 0
    Private Sub frmpedido_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        precio(0) = 8
        precio(1) = 6
        precio(2) = 10
        precio(3) = 12
        precio(4) = 9
        cboplatos.Text = cboplatos.Items.Item(0)
        btnagregar.Enabled = False
    End Sub
    Private Sub cboplatos_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboplatos.SelectedIndexChanged
        btnagregar.Enabled = True
        txtprecio.Text = Format(precio(cboplatos.SelectedIndex), "0.00")
        txtcantidad.Focus()

    End Sub

    Private Sub btnagregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnagregar.Click
        btnagregar.Enabled = False
        If lsbplatillo.Items.Count = i Then
            lsbplatillo.Items.Add(cboplatos.Text)
            lsbprecio.Items.Add(txtprecio.Text)
            lsbcantidad.Items.Add(txtcantidad.Text)
            i = i + 1
        End If
        lsbplatillo.Enabled = True : lsbprecio.Enabled = True
        lsbcantidad.Enabled = True
        txtcantidad.Text = ""
        txtprecio.Text = ""
    End Sub
    Private Sub txtcantidad_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtcantidad.Validated
        If txtcantidad.Text = "" Then
            txtcantidad.Focus()
        End If
    End Sub
    Private Sub txtcantidad_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcantidad.TextChanged
        If txtcantidad.Text = "" Then
            cboplatos.Enabled = False
        Else
            cboplatos.Enabled = True
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Visible = False

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim indice As Integer
        For indice = 0 To lsbprecio.Items.Count - 1
            w = w + Val(lsbprecio.Items.Item(indice)) * Val(lsbcantidad.Items.Item(indice))
            total = total + w
            w = 0
        Next
        TextBox1.Text = total
    End Sub
End Class